Skip to content

Conversation

@RalfJung
Copy link
Member

This is what @oli-obk and me agreed on here, except I went one step further and now require that for non-detected UB, CTFE continues in a reasonable way, instead of producing an arbitrary result. Once we keep the unoptimized MIR around, that is cheap to do. For example, this means that when the code violates alignment, CTFE must either raise an error or continue as if the pointer was actually well-aligned (and perform the appropriate load from the given region of memory). The previous wording would have allowed CTFE to return Undef when loading from an unaligned pointer -- I cannot see a good reason why we would permit CTFE to do that.

@RalfJung RalfJung mentioned this pull request Oct 31, 2020
[UB]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html

# Reference-level explanation
[reference-level-explanation]: #reference-level-explanation
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As usual I have no idea how to split the RFC intention across "guide-level" and "reference-level" explanation.^^ That separation makes very little sense to me, for most of the RFCs that I end up writing...

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-detected UB, CTFE continues in a reasonable way, instead of producing an arbitrary result.

yes, we should not permit CTFE to explicitly create bogus values on UB when, in order to do that, it would need to detect the UB and choose to create a bogus value. If UB is detected, interpretation must be aborted. If UB is not detected, CTFE continues in a reasonable way.

Co-authored-by: Oli Scherer <[email protected]>
@oli-obk oli-obk merged commit 33053bb into rust-lang:master Nov 2, 2020
@RalfJung RalfJung deleted the const-ub-rfc branch November 2, 2020 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants